/**
 * @author Lukas Koell
 * @author David Medenjak
 * @author Johannes Riedmann
 */
public class Test {

    private static final String hr =
            "-----------------------------------------------------------------------------------------";

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        /* Testing replaceableTree... */
        startTest("Testing ReplaceableTree...");
        StringTree test = new ReplaceableTree(null, null, null, "root");
        print("Added a root node...");
        System.out.println(test);
        test.add("david");
        test.add("thomas");
        test.add("lukas");
        test.add("Joko");
        test.add("Paul");
        test.add("Maya");
        test.add("Jassy");
        print("Added some names...");
        System.out.println(test);
        test("Contains joko?", test.contains("joko"));
        test("Contains Joko?", test.contains("Joko"));
        test("Find Jassy at:", test.search("Jassy"));
        test("Find Joko at:", test.search("Joko"));

        StringTree replace = new ReplaceableTree(null, null, null, "xkcd");
        replace.add("not");
        replace.add("a");
        replace.add("pointer");
        replace.add("-> odd");
        System.out.println(replace);
        ((ReplaceableTree) replace).replace("", replace.toString());
        System.out.println(replace);

        ((ReplaceableTree) test).replace("left", replace.toString());
        System.out.println(test);
        
        /* Testing intTree... */
        startTest("Testing IntTree...");
        IntTree test2 = new IntTree(15);
        print("Added a root node...");
        System.out.println(test2);
        test2.add(4);
        test2.add(5);
        test2.add(6);
        test2.add(7);
        test2.add(8);
        test2.add(9);
        test2.add(1);
        print("Added some numbers...");
        System.out.println(test2);
        test("Contains 4?", test2.contains(4));
        test("Contains 2?", test2.contains(2));
        test("Find 6 at:", test2.search(6));
        test("Find 9 at:", test2.search(9));

        IntTree replace2 = new IntTree(29);
        replace2.add(55);
        replace2.add(120);
        replace2.add(555);
        replace2.add(1337);
        System.out.println(replace2);
        replace2.replace("", replace2.toString());
        System.out.println(replace2);

        test2.replace("left", replace2.toString());
        System.out.println(test2);
        
        startTest("Testing the InorderTree...");
        System.out.println("order should be 3, 2, 1, 2, 5");
        SortedTree st = new InorderTree(null, null, null, "root3");
        st.add("root2");
        st.add("root1");
        st.add("root2");
        st.add("root5");
        System.out.println(st);
        print("traversion of the inorder tree:");
        System.out.println(st.traverse());
        
        startTest("Testing the Preorder Tree...");
        PreorderTree pt = new PreorderTree(null, null, null, "root3");
        pt.add("root2");
        pt.add("root1");
        pt.add("root2");
        pt.add("root5");
        System.out.println(pt);
        print("traversion of the preorder tree:");
        print(pt.traverse());
        
        startTest("Testing the Postorder Tree...");
        PostorderTree pot = new PostorderTree(null, null, null, "root3");
        pot.add("root2");
        pot.add("root1");
        pot.add("root2");
        pot.add("root5");
        System.out.println(pot);
        print("traversion of the postorder tree:");
        print(pot.traverse());
        
    }

    static private void startTest(String comment) {
        System.out.println(hr);
        System.out.println(">>> " + comment);
    }

    static private void test(String comment, Object output) {
        System.out.println("> " + comment + "\n" + output);
    }

    static private void print(String comment) {
        System.out.println("> " + comment);
    }
}
